package com.swf.seed.spring.resource;

import java.io.IOException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;
@Component
public class ResourceLoaderTest implements ResourceLoader,ResourceLoaderAware{
	private ResourceLoader resourceLoader;
	@Override
	public Resource getResource(String location) {
		return resourceLoader.getResource(location);
	}

	@Override
	public ClassLoader getClassLoader() {
		return resourceLoader.getClassLoader();
	}

	@Override
	public void setResourceLoader(ResourceLoader resourceLoader) {
		this.resourceLoader = resourceLoader;
		
	}
	
	public static void main(String[] args) throws IOException {
		ApplicationContext ac = new ClassPathXmlApplicationContext("springresource.xml");
		ResourceLoaderTest rl = ac.getBean(ResourceLoaderTest.class);
		Resource res = rl.getResource("classbook.xml");
		System.out.println(res.getDescription());
		System.out.println(res.getFile().exists());
	}
}
